import { RankBaseItem } from "./RankBaseItem";
import { GTextFormat } from "../../../common/GTextFormat";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { TToplist } from "../../../../Message/Db/Tables/TToplist";
import { Language } from "../../../../extend/language/Language";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { ColorConfig } from "../../resource/ColorConfig";
import { EToplistType } from "../../../../Message/Public/EToplistType";
import { PetUtil } from "../pet/info/PetUtil";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { SEntityId } from "../../../../Message/Public/SEntityId";
import { SEntityInfo } from "../../../../Message/BroadCast/SEntityInfo";
import { SPetInfo } from "../../../../Message/Game/SPetInfo";
import { PetOpRegister } from "../common/menu/PetOpRegister";
import { PetOpMenuConst } from "../common/menu/PetOpMenuConst";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
type int = number;
//class PetRankItem
    
    export  class PetRankItem extends RankBaseItem
    {
        constructor()
        {
            super();
            this.init();
            mouseChildren = false;
            return;
        }

        /* internal  */init(): void
        {
            this._tf = new GTextFormat("", 12, 11661311, false, false, false, null, null, flash.text.TextFormatAlign.CENTER);
            this._rankTxt = this.createTextField("", 0, 0, 25, 33, this._tf);
            this._nameTxt = this.createTextField("", 25, 0, 110, 33, this._tf);
            this._levelTxt = this.createTextField("", 128, 0, 45, 33, this._tf);
            this._ownerTxt = this.createTextField("", 170, 0, 100, 33, this._tf);
            this._campTxt = this.createTextField("", 240, 0, 125, 33, this._tf);
            this._attributeTxt = ObjCreate.createGTextField("", 340, 0, 58, 33, this, this._tf);
            this._attributeTxt.filters = [];
            this._rangeTxt = this.createTextField("", 375, 0, 120, 33, this._tf);
            this._bitmap = new Object /* flash.display.Bitmap */();
            var loc1=ObjCreate.createBg(0, 25, 460, 2, this, ImagesConst.SplitLine);
            return;
        }

        /* internal  */createTextField(arg1: string, arg2: int, arg3: int, arg4: int, arg5: int, arg6: Object /* flash.text.TextFormat */): Object /* flash.text.TextField */
        {
            var loc1=null;
            (loc1 = new Object /* flash.text.TextField */()).x = arg2;
            loc1.y = arg3;
            loc1.width = arg4;
            loc1.height = arg5;
            loc1.selectable = false;
            loc1.defaultTextFormat = arg6;
            loc1.text = arg1;
            addChild(loc1);
            return loc1;
        }

        public updateItem(arg1: TToplist, arg2: int): void
        {
            var loc5=null;
            var loc8=null;
            if (arg1 == null) 
            {
                this._rankTxt.text = "";
                this._nameTxt.text = "";
                this._levelTxt.text = "";
                this._ownerTxt.text = "";
                this._campTxt.text = "";
                this._attributeTxt.text = "";
                this._rangeTxt.text = "";
                _data = null;
                if (this._bitmap.parent) 
                {
                    removeChild(this._bitmap);
                }
                clearBgColor();
                return;
            }
            _data = arg1;
            var loc1=_data.rank;
            this._rankTxt.text = loc1.toString();
            this._levelTxt.text = Language.getStringByParam(28023, int(_data.propertyThree), _data.propertyTwo);
            this._ownerTxt.text = _data.ownerName;
            var loc2=_data.propertyOne;
            this._campTxt.text = GameDefConfig.instance.getECamp(loc2);
            var loc3=ColorConfig.instance.getCountryColor(loc2).intColor;
            var loc4=new GTextFormat("", 12, loc3, false, false, false, null, null, flash.text.TextFormatAlign.CENTER);
            this._campTxt.setTextFormat(loc4);
            var loc6="";
            if (arg2 != EToplistType._EToplistTypePetGrowth) 
            {
                if (arg2 != EToplistType._EToplistTypePetSpirit) 
                {
                    this._attributeTxt.text = _data.valueOne.toString();
                    this._attributeTxt.toolTipData = "";
                    this._nameTxt.text = _data.entityName;
                }
                else if (loc5 = PetUtil.getSpiritTitle(_data.valueOne)) 
                {
                    loc6 = ColorConfig.instance.getItemColor(loc5.color).color;
                    this._nameTxt.htmlText = HTMLUtil.addColor(_data.entityName, loc6);
                    this._attributeTxt.htmlText = HTMLUtil.addColor(_data.valueOne + " · " + loc5.title, loc6);
                    this._attributeTxt.toolTipData = PetUtil.getSpiritTitleTipData(_data.valueOne);
                }
                else 
                {
                    this._nameTxt.htmlText = _data.entityName;
                    this._attributeTxt.htmlText = _data.valueOne + "";
                }
            }
            else if (loc5 = PetUtil.getGrowthTitle(_data.valueOne)) 
            {
                loc6 = ColorConfig.instance.getItemColor(loc5.color).color;
                this._nameTxt.htmlText = HTMLUtil.addColor(_data.entityName, loc6);
                this._attributeTxt.htmlText = HTMLUtil.addColor(_data.valueOne + " · " + loc5.title, loc6);
                this._attributeTxt.toolTipData = PetUtil.getGrowthTitleTipData(_data.valueOne);
            }
            else 
            {
                this._nameTxt.htmlText = _data.entityName;
                this._attributeTxt.htmlText = _data.valueOne + "";
            }
            if (this._bitmap.parent) 
            {
                removeChild(this._bitmap);
            }
            var loc7=_data.lastRank;
            var loc9=true;
            if (loc7 != 0) 
            {
                if (loc1 > loc7) 
                {
                    this._bitmap = GlobalClass.getBitmap(ImagesConst.RangeDecline);
                    loc8 = (loc1 - loc7).toString();
                }
                else if (loc1 < loc7) 
                {
                    this._bitmap = GlobalClass.getBitmap(ImagesConst.RangeRaise);
                    loc8 = (loc7 - loc1).toString();
                }
                else if (loc1 == loc7) 
                {
                    this._bitmap = GlobalClass.getBitmap(ImagesConst.RangeSame);
                    loc8 = "";
                }
            }
            else 
            {
                loc9 = false;
                loc8 = Language.getString(32078);
            }
            if (loc9) 
            {
                this._bitmap.x = 418;
                this._bitmap.y = 2;
                addChild(this._bitmap);
            }
            this._rangeTxt.text = loc8.toString();
            this.initPetMenuInfo();
            return;
        }

        /* internal  */initPetMenuInfo(): void
        {
            var loc1=new SEntityId();
            loc1.id = _data.ownerId;
            loc1.type = 1;
            loc1.typeEx = _serverId;
            this._entityInfo = new SEntityInfo();
            this._entityInfo.entityId = loc1;
            this._petInfo = new SPetInfo();
            this._petInfo.uid = _data.entityUid;
            return;
        }

        public onPetItemClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (_data != null) 
            {
                drawGrayColor();
                PetOpRegister.UnRegister(arg1.target as Object /* flash.display.InteractiveObject */);
                PetOpRegister.Register(arg1.target as Object /* flash.display.InteractiveObject */, this._entityInfo, PetOpMenuConst.RankOpMenu, this._petInfo);
            }
            return;
        }

        /* internal */ /* var */_tf: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_rankTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_levelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_ownerTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_campTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_attributeTxt: GTextFiled;

        /* internal */ /* var */_rangeTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_bitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_entityInfo: SEntityInfo;

        /* internal */ /* var */_petInfo: SPetInfo;
    }
